#####################################
# Dyadic Ratio algorithm: DENMARK   #
# Appendix table3                   #
#####################################


###load library
library(openxlsx)
library(psych)
library(ggplot2)
library(gridExtra)
library(tidyverse)

###usa macropartisanship_extract
# "extract.R" should be obtained from James Stimson's HP
# URL: https://stimson.web.unc.edu/software/
source("extract.R")

#load data
de<-read.csv("denmark_extract.csv")
attach(de)
describe(de)
de<-na.omit(de)

#setting time-series information
varname<-de$VARNAME
date<-as.Date(YearMon)
index<-de$value
ncases<-NULL

#using "extract" to compute macropartisanship
output_denmark<-extract(varname,date=date,index,ncases,begindt=ISOdate(1960,1,1),
                enddt = ISOdate(2019,6,1), unit="M",npass=2)
display(output_denmark)
summary(output_denmark)





#factor scores of 2 dimensions
mpartisan1_denmark<-output_denmark$latent1
mpartisan2_denmark<-output_denmark$latent2
YEAR<-1960:2019


